<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
sss
           <#--<#list users as user>-->
           <#--<tr>-->
               <#--<th>${user.id}</th>-->
               <#--<th>${user.name}</th>-->
               <#--<th>${user.sex}</th>-->
               <#--<th>${user.constellation}</th>-->
               <#--<th>${user.phone}</th>-->
           <#--</tr>-->
           <#--</#list>-->
<#-- 表格服务端分页：完美简单实现 http://v4-alpha.getbootstrap.com/components/pagination/-->
<#--总页数-->
<#assign totalPages = users.totalPages>
<#--总元素数-->
<#assign totalElements = users.totalElements>
<#--当前页数 加1是因为java传过来的page是以0开始的 -->
<#assign number = users.number+1>
<#--第一页-->
<#assign first = users.first>
<#--最后一页-->
<#assign last = users.last>
<#list users as user>

<tr>
<th>${user.id}</th>
<th>${user.name}</th>
<th>${user.sex}</th>
<th>${user.constellation}</th>
<th>${user.phone}</th>
</tr>

<nav aria-label="Page navigation">
    <ul class="pagination pagination-lg  justify-content-center">

    <#--上一页-->
    <#if first>
        <li class="page-item">
            <a class="page-link" href="#">上一页</a>
        </li>
    <#else>
        <li class="page-item">
            <a class="page-link" href="user?page=${number-2}&size=5'">上一页</a>
        </li>
    </#if>

    <#--小于等于10页全部显示-->
    <#if totalPages <= 10>
        <#list 1..totalPages as pageIndex>
            <#if number == pageIndex>
                <li class="page-item active">
                    <a class="page-link" href="user?page=${pageIndex-1}&size=5'">${pageIndex}</a>
                </li>
            <#else>
                <li class="page-item ">
                    <a class="page-link" href="user?page=${pageIndex-1}&size=5'">${pageIndex}</a>
                </li>
            </#if>
        </#list>
    </#if>
    <#--大于10页：显示前5页，最后3页，中间用 ...-->
    <#if totalPages gt 10>
    <#--显示前5页-->
        <#list 1..5 as pageIndex>
            <#if number == pageIndex>
                <li class="page-item active">
                    <a class="page-link" href="user?page=${pageIndex-1}&size=5'">${pageIndex}</a>
                </li>
            <#else>
                <li class="page-item">
                    <a class="page-link" href="user?page=${pageIndex-1}&size=5'">${pageIndex}</a>
                </li>
            </#if>
        </#list>

    <#--中间部分的显示 ...  number: currentPage, 区间逻辑的判断-->
        <#if number == 6 >
            <li class="page-item active">
                <a class="page-link" href="user?page=${number}&size=20">${number}</a>
            </li>
            <li class="page-item">
                <a class="page-link" href="#">...</a>
            </li>
        <#elseif number == totalPages-3>
            <li class="page-item">
                <a class="page-link" href="#">...</a>
            </li>
            <li class="page-item active">
                <a class="page-link" href="user?page=${number}&size=20">${number}</a>
            </li>
        <#elseif number gt 6 && number lt totalPages-3>
            <li class="page-item">
                <a class="page-link" href="#">...</a>
            </li>
            <li class="page-item active">
                <a class="page-link" href="user?page=${number}&size=20">${number}</a>
            </li>
            <li class="page-item">
                <a class="page-link" href="#">...</a>
            </li>
        <#else>
            <li class="page-item">
                <a class="page-link" href="#">...</a>
            </li>
        </#if>

    <#--显示最后3页-->
        <#list totalPages-2..totalPages as pageIndex>
            <#if number == pageIndex>
                <li class="page-item active">
                    <a class="page-link" href="user?page=${pageIndex-1}&size=5">${pageIndex}</a>
                </li>
            <#else>
                <li class="page-item">
                    <a class="page-link" href="user?page=${pageIndex-1}&size=5">${pageIndex}</a>
                </li>
            </#if>
        </#list>
    </#if>

    <#--下一页-->
    <#if last>
        <li class="page-item">
            <a class="page-link" href="#">下一页</a>
        </li>
    <#else>
        <li class="page-item">
            <a class="page-link" href="user?page=${number}&size=5">下一页</a>
        </li>
    </#if>
    </ul>
    <div class="center">总共 ${totalPages} 页， ${totalElements} 条记录</div>
</nav>
</#list>
</body>
</html>